package com.thermal.thermal_inspection.service;

import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.function.Supplier;

public interface CacheService {
    /**
     *从缓存中获取数据，若缓存中不存在，则从数据源中获取并存入缓存
     */
    <T, R> T getOrLoad(String key, Function<R, T> dataLoader, R input, long timeout, TimeUnit timeUnit);

    /**
     *无参数，从缓存中获取数据，若缓存中不存在，则从数据源中获取并存入缓存
     */
    <T> T getOrLoad(String key, Supplier<T> dataLoader, long timeOut, TimeUnit timeUnit);

    /**
     * 存入键值对
     */
    <R> void put(String key, R input, long timeout, TimeUnit timeUnit);

    /**
     * 取出键值对
     */
    <T> T get(String key);

}
